<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no, width=device-width"/>
    <title>地图导航</title>
    <style>
        *{
            margin:0;
            padding:0px
        }
        html,
        body,
        #container {
          width: 100%;
          height: 100%;
          background-color: #ccc;
        }
    </style>
</head>
<body>
<div id="container"></div>
<script type="text/javascript">
    window._AMapSecurityConfig = {
      securityJsCode: "ceba8e34cf71f6d5fb16000caa70e058",
    };
</script>
<script type="text/javascript" src="https://webapi.amap.com/maps?v=2.0&key=c8fdda62e98d13baa5fb7b1685a04e2a"></script>
<script type="text/javascript">
    //地图初始化应该在地图容器div已经添加到DOM树之后
    var map = new AMap.Map("container", {
      zoom: 18,
      center:[114.298572, 30.584355],//中心点坐标
    });
    //路径导航
     function beginDriving(start,end){
        //引入和创建驾车规划插件
        AMap.plugin(["AMap.Driving"], function () {
        const driving = new AMap.Driving({
            map: map,
            //驾车策略，包括 LEAST_TIME，LEAST_FEE, LEAST_DISTANCE,REAL_TRAFFIC
            policy: AMap.DrivingPolicy.LEAST_TIME
        });
        //获取起终点规划线路
        const points = [
            { keyword: start}, //起始点坐标
            { keyword: end} //终点坐标
            ]
        driving.search(points, function (status, result) {
            if (status === "complete") {
            //status：complete 表示查询成功，no_data 为查询无结果，error 代表查询错误
            //查询成功时，result 即为对应的驾车导航信息
                console.log(result);
            } else {
                console.log("获取驾车数据失败：" + result);
            }
        });
        });
    }
    //beginDriving("北京天安门","乌鲁木齐")
</script>
</body>
</html>